Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix error: cannot use 'try' with exceptions disabled in Win LLVM Clang #4208

Merged
merged 1 commit into from
Oct 23, 2024

Conversation

sergio-nsk
Copy link
Contributor

Fixes #4207.

LLVM Clang on Windows does not define __GNUC__. The preprocessor falls to #elif FMT_MSC_VERSION && !_HAS_EXCEPTIONS with _HAS_EXCEPTIONS 1 defined in vcruntime.h:104.

@sergio-nsk
Copy link
Contributor Author

sergio-nsk commented Oct 20, 2024

Other GCC related macros undefined in LLVM Clang on Windows:

#define __GCC_ASM_FLAG_OUTPUTS__ 1
< #define __GCC_ATOMIC_BOOL_LOCK_FREE 2
< #define __GCC_ATOMIC_CHAR16_T_LOCK_FREE 2
< #define __GCC_ATOMIC_CHAR32_T_LOCK_FREE 2
< #define __GCC_ATOMIC_CHAR_LOCK_FREE 2
< #define __GCC_ATOMIC_INT_LOCK_FREE 2
< #define __GCC_ATOMIC_LLONG_LOCK_FREE 2
< #define __GCC_ATOMIC_LONG_LOCK_FREE 2
< #define __GCC_ATOMIC_POINTER_LOCK_FREE 2
< #define __GCC_ATOMIC_SHORT_LOCK_FREE 2
< #define __GCC_ATOMIC_TEST_AND_SET_TRUEVAL 1
< #define __GCC_ATOMIC_WCHAR_T_LOCK_FREE 2
  #define __GCC_CONSTRUCTIVE_SIZE 64
  #define __GCC_DESTRUCTIVE_SIZE 64
< #define __GCC_HAVE_DWARF2_CFI_ASM 1
  #define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_1 1
  #define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_2 1
  #define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_4 1
  #define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_8 1
< #define __GLIBCXX_BITSIZE_INT_N_0 128
< #define __GLIBCXX_TYPE_INT_N_0 __int128
< #define __GNUC_GNU_INLINE__ 1
< #define __GNUC_MINOR__ 2
< #define __GNUC_PATCHLEVEL__ 1
< #define __GNUC__ 4
< #define __GNUG__ 4
< #define __GXX_ABI_VERSION 1002
< #define __GXX_EXPERIMENTAL_CXX0X__ 1
< #define __GXX_RTTI 1
< #define __GXX_WEAK__ 1
#define __INT16_C_SUFFIX__

@mwinterb
Copy link
Contributor

clang-cl seems to define _CPPUNWIND, which is the define that Microsoft lists in their predefined macros documentation.

@sergio-nsk
Copy link
Contributor Author

sergio-nsk commented Oct 21, 2024

@mwinterb You are right, _CPPUNWIND and __cpp_exceptions instead of _HAS_EXCEPTIONS are defined. Which one to use in this change?

Clang uses #if defined(__cpp_exceptions) && __cpp_exceptions >= 199711L. So I make the same check.

@sergio-nsk sergio-nsk marked this pull request as draft October 21, 2024 22:59
@sergio-nsk sergio-nsk marked this pull request as ready for review October 21, 2024 23:19
@vitaut
Copy link
Contributor

vitaut commented Oct 23, 2024

Please apply clang-format.

@@ -146,6 +146,8 @@
// Use the provided definition.
#elif defined(__GNUC__) && !defined(__EXCEPTIONS)
# define FMT_USE_EXCEPTIONS 0
#elif defined(__clang__) && (!defined(__cpp_exceptions) || __cpp_exceptions < 199711L)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder why they check against 199711L?

Copy link
Contributor Author

@sergio-nsk sergio-nsk Oct 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IDK. As I mentioned, this is how Clang does that C++ exceptions check.

Maybe very older clang set it to some lower value and __cpp_exceptions < 199711L can be removed since such old clang cannot be used with {fmt}.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest removing the __cpp_exceptions < 199711L part then if it works in your environment.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it works.

Fixes fmtlib#4207.

LLVM Clang on Windows does not define `__GNUC__`. The preprocessor falls
to `#elif FMT_MSC_VERSION && !_HAS_EXCEPTIONS` with `_HAS_EXCEPTIONS 1`
defined in vcruntime.h:104.
@vitaut vitaut merged commit 4daa3d5 into fmtlib:master Oct 23, 2024
45 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

fmt/include\fmt/format-inl.h:1417:3: error: cannot use 'try' with exceptions disabled
3 participants